package excerciseFour1;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int[] a=new int[101];
		int[] b=new int[101];
		int[] c=new int[101];
		int counta=0,countb=0,count=0;
		int temp;
		int flag=0;
		while(in.hasNext()){
			counta++;
			temp=in.nextInt();
			if(counta%2==1){
				a[temp]=in.nextInt();
				counta++;
			}
			if(temp==0)break;
		}
		while(in.hasNext()){
			countb++;
			temp=in.nextInt();
			if(countb%2==1){
				b[temp]=in.nextInt();
				countb++;
			}
			if(temp==0)break;
		}
		for(int i=0;i<c.length;i++){
			c[i]=a[i]+b[i];
			if(c[i]!=0){
				count++;
			}
		}
		if(count==0){
			count++;
			System.out.print(c[0]);
			return;
		}
		int num=0;
		for(int i=c.length-1;i>=0;i--){
			if(num==count)break;
			if(c[i]!=0){
				if(i==0){
					num++;
					if(c[i]>0){
						System.out.print("+");
						System.out.print(c[i]);
					}else{
						System.out.print(c[i]);
					}
				}
				else if(i==1){
					num++;
					if(c[i]==1){
						if(num==1){
							System.out.print("x");
						}else{
								System.out.print("+");
								System.out.print("x");
						}
					}else{
						if(num==1){
							System.out.print(c[i]+"x");
						}else{
							if(c[i]<0){
								System.out.print(c[i]+"x");
							}else{
								System.out.print("+");
								System.out.print(c[i]+"x");
							}
						}
					}
					
					
				}
				else {
					if(c[i]==1){
						num++;
						if(num==1){
							System.out.print("x"+i);
						}else{
							System.out.print("+");
							System.out.print("x"+i);
						}
					}
					else{
						num++;
						if(num==1){
							System.out.print(c[i]+"x"+i);
						}else{
							if(c[i]<0){
								System.out.print(c[i]+"x"+i);
							}else{
								System.out.print("+");
								System.out.print(c[i]+"x"+i);
							}
						}
						
					}
				}
			}
		}
	}

}
